package com.chixing.day12_date_factory;


import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

public class DateUtil {

    /*
    * 字符串转换成LocalDateTime对象
    * */
    public static LocalDateTime stringToLocalDateTime(String str){
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
        return LocalDateTime.parse(str,formatter);
    }
    /**
     * 字符串转换成LocalDate对象
     */
    public static LocalDate stringToLocalDate(String str){
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
        return LocalDate.parse(str,formatter);
    }
    /**
     * 字符串转换成LocalTime对象
     */
    public static LocalTime stringToLocalTime(String str){
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss");
        return LocalTime.parse(str,formatter);
    }
    /**
     * 将LocalDateTime转换成字符串
     */
    public static String localDateTimeToDtring(LocalDateTime localDateTime){
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
        return localDateTime.format(formatter);
    }
    /**
     * 将LocalDate转换成字符串
     */
    public static String localDateToString(LocalDate localDate){
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
        return  localDate.format(formatter);
    }
    /**
     * 将LocalTime转换成字符串
     */
    public static String localTimeToString(LocalTime localTime){
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss");
        return localTime.format(formatter);
    }

}
